package edu.thu.studio.ormdesigner.model.diagram;

import com.thoughtworks.xstream.annotations.XStreamAlias;

import edu.thu.studio.ormdesigner.model.AbstractObjectModel;
import edu.thu.studio.ormdesigner.model.diagram.link.LinkSet;
import edu.thu.studio.ormdesigner.model.diagram.node.NodeSet;
import edu.thu.studio.ormdesigner.model.diagram.note.NoteSet;
import edu.thu.studio.ormdesigner.model.diagram.style.StyleSet;
import edu.thu.studio.ormdesigner.util.Properties;
import edu.thu.studio.ormdesigner.util.Utils;

@XStreamAlias("diagram")
public class Diagram extends AbstractObjectModel {
    
    private static final long serialVersionUID = 6998985022414351214L;
    
    @XStreamAlias("links")
    private LinkSet links = new LinkSet();
    
    @XStreamAlias("nodes")
    private NodeSet nodes = new NodeSet();
    
    @XStreamAlias("notes")
    private NoteSet notes = new NoteSet();
    
    @XStreamAlias("styles")
    private StyleSet styles = new StyleSet();
    
    public Diagram() {
    }
    
    public LinkSet getLinks() {
        return links;
    }
    
    public void setLinks(LinkSet links) {
        this.links = links;
    }
    
    public NodeSet getNodes() {
        return nodes;
    }
    
    public void setNodes(NodeSet nodes) {
        this.nodes = nodes;
    }
    
    public NoteSet getNotes() {
        return notes;
    }
    
    public void setNotes(NoteSet notes) {
        this.notes = notes;
    }
    
    public StyleSet getStyles() {
        return styles;
    }
    
    public void setStyles(StyleSet styles) {
        this.styles = styles;
    }
    
    public void merge(Diagram newDiagram) {
        this.setCode(newDiagram.getCode());
        this.setName(newDiagram.getName());
        this.setComment(newDiagram.getComment());
    }
    
    public void checkAndInit() {
        if (null == id) {
            id = Utils.getUUID();
        }
        if (null == code) {
            code = Properties.editor_newdiagram_code;
        }
        if (null == name) {
            name = Properties.editor_newdiagram_name;
        }
    }
    
    public void refreshChildren() {
        if (isUpdateable()) {
            this.firePropertyChange("refreshChildren", null, null);
        }
    }
    
}
